<?php
/**
 * 5折购ajax
 * Created by diandong.
 * User: cdd
 * Date: 14-10-22
 * Time: 上午9:53
 */
quanli_require('module/func/eai.func.php');
quanli_require('module/base/activity/activitySpike.class.php');

class ajax_discount{

    public function execute() {

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch($_REQUEST['operFlg']) {

                case 1://验证会员是否具有五折权利
                    $this->checkFive();
                    break;


            }

        } else {

            $this->toReturn('参数错误');

        }

    }

    //产讯会员是否具有五折权利
    function checkFive(){

       global $G_SHOP;
        //实例化五折促销类
        $activityspike=new activitySpike();

        //当前会员是否具有5折购的资格
        /*
         * pcustID 会员ID
         * bill_status 订单状态
         * billPromotion 促销渠道ID
         */
        $sql = "SELECT COUNT(*) AS num FROM cust_master WHERE  pcustID =(SELECT pcustID FROM bill_master WHERE pcustID = ?  AND bill_status <> ? AND billPromotion = ? and createTime > ? and  createTime < ? )";
        $isFive=$G_SHOP->DBCA->stmt_query($sql,'iiiss',$G_SHOP->currentPCustID,10,$activityspike->billPromotion_lv5,date('Y').'-01-01 00:00:00',date('Y').'-12-31 23:59:59');

        $sql_rank='select rankID from cust_master where pcustID=?';
        $isRankID=$G_SHOP->DBCA->stmt_query($sql_rank,'i',$G_SHOP->currentPCustID);

        $isFivePower=0;//五折权利 赋初值
        if($isFive[0]->num==0 && $isRankID[0]->rankID==5){
            //会员等级LV5 并且 没有使用五折优惠的具有五折购的权利
            $isFivePower=1;
        }
        if($isFivePower==1){
            returnJsonData($_REQUEST['post_id'], 200);
        }else{
            returnJsonData('不具备五折购资格', 400);
        }
    }































}